package com.tyqx.hashchainbiz.controller.useProduct;

import com.tyqx.hashchainbean.module.NeedProduct;
import com.tyqx.hashchainbean.module.ProducePlan;
import com.tyqx.hashchainbean.vo.NeedProductVO;
import com.tyqx.hashchainbean.vo.ProducePlanVO;
import com.tyqx.hashchainbean.vo.QueryParamVo;
import com.tyqx.hashchainbean.vo.QueryTimeParamVo;
import com.tyqx.hashchainbiz.service.NeedProductService;
import com.tyqx.hashchainbiz.service.QueryDonateService;
import com.tyqx.hashchainbiz.service.TrackDonateService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "需求物资")
@RestController
@RequestMapping("/needProduct")
@CrossOrigin
public class NeedProductController {

    @Resource
    private NeedProductService needProductService;

    @RequestMapping(value="/saveNeedProduct", method = RequestMethod.POST)
    @ResponseBody
    public String saveNeedProduct(@RequestBody NeedProductVO needProductVO) throws Exception {

        String msg="";
        NeedProduct needProduct=new NeedProduct();
        needProduct.setNeedName(needProductVO.getNeedName());
        needProduct.setNeedNum(needProductVO.getNeedNum());
        needProduct.setNeedPerson(needProductVO.getNeedPerson());
        needProduct.setNeedPrice(needProductVO.getNeedPrice());
        needProduct.setNeedTime(needProductVO.getNeedTime());
        needProduct.setNeedUnit(needProductVO.getNeedUnit());
        needProduct.setUserName(needProductVO.getUserName());
        if(needProductService.needProduct(needProduct)>0){
            msg="添加需求物资成功";
        }else{
            msg="添加需求物资失败";
        }
        return msg;
    }

    @RequestMapping(value="/getNeedProductById", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<NeedProduct> getNeedProductById(@RequestBody QueryParamVo queryParamVo) throws Exception {

        return needProductService.getNeedProductById(queryParamVo.getDonateId(),queryParamVo.getUserName());
    }

    @RequestMapping(value="/getNeedProductByTime", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<NeedProduct> getNeedProductByTime(@RequestBody QueryTimeParamVo queryTimeParamVo) throws Exception {

        return needProductService.getNeedProductByTime(queryTimeParamVo.getStartTime(),
                queryTimeParamVo.getEndTime(),queryTimeParamVo.getUserName());
    }
}
